package com.chinamsp.dydb.query;

import com.chinamsp.dydb.query.impl.SimpleSymbolConverter;
import com.chinamsp.dydb.query.impl.SimpleValueConverter;

/**
 * 表达式类型
 * @author shifenghu
 *
 */
public enum SymbolType {

	/**
	 * 大于等于
	 */
	GE("ge", ">=", "大于等于"),
	
	/**
	 * 小于等于
	 */
	LE("le", "<=", "小于等于"),
	
	/**
	 * 大于
	 */
	GT("gt", ">", "大于"),
	
	/**
	 * 小于
	 */
	LT("lt", "<", "小于"),
	
	/**
	 * 等于
	 */
	EQ("eq", "=", "等于"),
	
	/**
	 * 不等于
	 */
	NQ("nq", "!=", "不等于"),
	
	/**
	 * 不在 ... 里
	 */
	NOT_IN("notin", "not in", "不在...里"),
	
	/**
	 * 在 ... 里
	 */
	IN("in", "in", "在...里"),
	
	
	/**
	 * 模糊匹配
	 */
	LK("like", "like", "模糊匹配"),
	
	/**
	 * 左侧模糊匹配，类似 like '%xxxx'
	 */
	LLK("llk", "llike", "左侧模糊匹配"),
	
	
	/**
	 * 右侧模糊匹配，类似 like 'xxx%'
	 */
	RLK("rlk", "rlike", "右侧模糊匹配"),

	/**
	 * 不为空
	 */
	NOT_NULL("nnl", "not null", "匹配不为空"),
	
	/**
	 * 为空
	 */
	IS_NULL("enl", "is null", "匹配为空")
	;
	
	/**
	 * 简称
	 */
	private String type;
	
	/**
	 * 对应的数据库表达式
	 */
	private String sqlExpression;
	
	/**
	 * 描述
	 */
	private String desc;
	
	/**
	 * 表达式 转换服务
	 */
	private BaseSymbolConverter expCoverter;
	
	/**
	 * 值转换
	 */
	private BaseValueConverter valueConverter;
	
	private SymbolType(String type, String sqlExpression, String desc) {
		this(type, sqlExpression, desc, SimpleSymbolConverter.INSTANCE, SimpleValueConverter.INSTANCE);
	}
	
	private SymbolType(String type, String sqlExpression, String desc, BaseSymbolConverter expCoverter, BaseValueConverter valueConverter) {
		this.type = type;
		this.sqlExpression = sqlExpression;
		this.desc = desc;
		this.expCoverter = expCoverter;
		this.valueConverter = valueConverter;
	}

	public String getType() {
		return type;
	}

	public String getSqlExpression() {
		return sqlExpression;
	}

	public String getDesc() {
		return desc;
	}
	
	public BaseSymbolConverter getExpCoverter() {
		return expCoverter;
	}

	public BaseValueConverter getValueConverter() {
		return valueConverter;
	}

	/**
	 * 根据 type str 获取 expresion type 
	 * @param type
	 * @return
	 */
	public static SymbolType byType(String type) {
		for (SymbolType t : SymbolType.values()) {
			if (t.type.equalsIgnoreCase(type)) {
				return t;
			}
		}
		return null;
	}
	
}
